package com.lry.basic.spring.aop.face;

import com.lry.basic.spring.aop.core.CglibDynamicAopProxy;
import com.lry.basic.spring.aop.core.JdkDynamicAopProxy;
import com.lry.basic.spring.ioc.BeanFactory;

import java.util.List;

public class DefaultAopProxyFactory implements AopProxyFactory{

    @Override
    public AopProxy createAopProxy(Object bean, String beanName, List<Advisor> matchAdvisors, BeanFactory beanFactory) {
        // 是该用jdk动态代理还是cglib？
        if (shouldUseJDKDynamicProxy(bean, beanName)) {
            return new JdkDynamicAopProxy(beanName, bean, matchAdvisors, beanFactory);
        } else {
            return new CglibDynamicAopProxy(beanName, bean, matchAdvisors, beanFactory);
        }
    }

    private boolean shouldUseJDKDynamicProxy(Object bean, String beanName) {
        // 如何判断？有实现接口就用JDK,没有就用cglib？
        return false;
    }

}
